<div class="content">

   	<div class="list_button">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
        <tr>
            <td>
                <?php
					echo CHtml::link(
						"<div class='button'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
							"</div>" .
							"<div style='float:left; min-width:80px;'>".
								"Thêm mới" .
							"</div>" .
						"</div>"
						,
                       array($this->controller_id."/add","page"=>$page)
                    );
					
					echo "<div class='button' id='delete_multi'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png") .
							"</div>" .
							"<div style='float:left; min-width:40px;'>".
								"Xóa" .
							"</div>" .
						"</div>";
					          
                ?>
                <script language="javascript">
                $(document).ready(function(){
                    $('#delete_multi').click(function(){
                        var form = document.getElementById("form_table_all");
                        form.submit();
                    });	
                })
              </script>
            </td>
            
            <td align="right">
               
             </td>
          </tr>
        </table>
	</div>



    <table class="view">
        <tr height='25'>
            <th width="50px"> # </th>
            <th width="30">
                <?php 
                    echo CHtml::checkBox("checkbox_all", false, array("id"=>"checkbox_all"));
                ?>
            </th>
            <th colspan="2">Action</th>
            <th>Shortcut</th>
            <th width="80">Bật/Tắt</th>
            <th width="100">
            	<?php 
					echo CHtml::link(
						"Thứ tự",
						array($this->controller_id."/set_order", "page"=>$page),
						array("title"=>"Tạo thứ tự mặc định")
					);
					echo " ";
					echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-saveorder.png", "", 
						array("style"=>"cursor:pointer", "id"=>"id_save_order"));

				?>
            </th>
            <script language="javascript">
				$(document).ready(function(){
					$('#id_save_order').click(function() {
						var form = document.getElementById("form_table_all");
						form.action = '<?php
							$url = Yii::app()->createUrl(
								$this->route."/save_order",
								array("page"=>$page)
							);
							echo $url;
						?>';
						form.submit();
						//alert(form.action);
					});
				});
			</script>
            <th width="180">Admin Menu</th>
            <th width="50">ID</th>
        </tr>
        <?php
            if (! is_null($rows))
            {
                echo CHtml::beginForm(
					array(
						$this->controller_id."/delete_multi", 
						"page"=>$page
					),
					"post",
                    array("id"=>"form_table_all")
				);
                
                $i = 1;
                foreach($rows as $row)
                {
                    echo "<tr height='25'>";
                        echo "<td align='center'>";
                            echo $i++;
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo CHtml::checkBox("cib[".$row["id"]."]", false, array("id"=>"cb".$i));
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
							$url = Yii::app()->createUrl(
								$this->route."/delete",
								array(
									"shortcut_id" => $row->id,
									"page" => $page
								)
							);
							echo CHtml::image(
								Yii::app()->baseUrl.'/assets/icon/icon-16-trash.png',
								"",
								array(
									"style"=>"cursor:pointer",
									"title"=>"Delete",  
									"onClick"=>"javascript:actionDelete('".$url."');"
								)
							);
							
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/icon-16-edit.png'),
                                array(
                                    $this->controller_id."/edit",
                                    "shortcut_id" => $row["id"],
                                    "page" => $page
                                ),
                                array('title'=>'edit')
                            );
                        echo "</td>";
                            
                        echo "<td>";
                            echo CHtml::link(	
                                $row["name"],
                                array(
                                    $this->controller_id."/edit",
                                    'shortcut_id' => $row["id"],
                                    "page" => $page
                                ),
                                array('title'=>'Edit')
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            $icons =  array(
                                0 => "icon-16-remove.png",
                                1 => "icon-16-tick.png",
                            );
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/'.$icons[$row["enable"]]),
                                array($this->controller_id."/enable", 
                                    "shortcut_id"=>$row["id"],
                                    "page" => $page
                                )
                            );
                        echo "</td>";
                        
						echo "<td align='right'>";
                            echo CHtml::textField(
								"order[".$row->id."]",
								$row->order,
								array("style"=>"width:40px; text-align:right; 
									padding:3px; color:#f00; font-size:11px;")
							);
							echo " ";
						
						
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-up.png"),
								array(
									$this->controller_id."/up",  
									"shortcut_id" => $row->id, 
									"page" => $page
								)
							);
						
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-down.png"),
								array(
									$this->controller_id."/down", 
									"shortcut_id" => $row->id, 
									"page" => $page
								)
							);
						
                        echo "</td>";
						
						echo "<td align='left'>";
                           	$adminmenu = adminmenu::model()->findByPk($row->adminmenu_id);
						   	if ($adminmenu->parent_id == 0)
						   		echo $adminmenu->name_default;
							else
							{
								$parent = adminmenu::model()->findByPk($adminmenu->parent_id);
								echo $parent->name_default ."/" . $adminmenu->name_default;
							}
                        echo "</td>";
						
                        echo "<td align='center'>";
                            echo $row["id"];
                        echo "</td>";
						
                    echo "</tr>";        
                }
                
                echo CHtml::endForm(); // end form
            }
        ?>
    </table>
</div><!-- end div content -->

<?php 
	// display pagination
	if ($pages->pageCount > 1)
	{
		echo "<div class='pagination'>";
			$this->widget('CLinkPager', array(
				'header' => "",
				'cssFile' => Yii::app()->baseUrl."/assets/css/pager.css",
				"prevPageLabel" => "Trang trước",
				"nextPageLabel" => "Trang sau",
				'pages' => $pages,
			));
			
			$this->widget('CListPager', array(
				//"promptText" => "Chuyển nhanh",
				"header" => "Trang ",
				'pages'=>$pages
			));
		echo "</div>";
	}
?>

<script language="javascript">
function actionDelete(url)
{
	if (confirm("Bạn muốn xóa mẫu tin này ?") == true)
		window.location = url;
}
</script>
    